<!--
 * @Author: guojinxin_hub 1907745233@qq.com
 * @Date: 2024-09-04 15:13:48
 * @LastEditors: guojinxin_hub 1907745233@qq.com
 * @LastEditTime: 2024-09-04 15:51:10
 * @FilePath: \feidu-initialization-framework\src\components\Icon\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <i v-if="isElementUiIcon" :class="iconName"> </i>
  <span :title="title" v-else>
    <svg class="svg-icon" aria-hidden="true">
      <use :xlink:href="iconName"></use>
    </svg>
  </span>
</template>

<script>
import {
  computed,
  defineComponent,
  reactive,
  ref,
  toRefs,
  watchEffect,
} from 'vue'

export default defineComponent({
  name: 'icon',
  props: ['title', 'icon', 'fontSize', 'color'],
  setup(props) {
    const _this = reactive({
      iconName: computed(() => {
        if (props.icon.includes('el-icon')) {
          return props.icon
        }
        return `#icon-${props.icon}`
      }),
    })

    const isElementUiIcon = ref(false)
    watchEffect(() => {
      isElementUiIcon.value = _this.iconName.includes('el-icon')
    })

    return {
      ...toRefs(_this),
      isElementUiIcon,
    }
  },
})
</script>

<style lang="scss" scoped>
i {
  font-size: calc(1vw * #{$heightRatio} * v-bind(fontSize));
  color: v-bind(color);
}

span {
  // font-size: 16px;
  font-size: calc(1vw * #{$heightRatio} * v-bind(fontSize));
  color: v-bind(color);
  transition: color 0.3s;
  display: flex;
  align-items: center;
}

.svg-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
  cursor: pointer;
}
</style>
